﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;

public partial class DetailsProduct : System.Web.UI.Page
{
    ShopDataContext ds = new ShopDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
       if(!IsPostBack){
           if (Request.QueryString["pCode"] !=null)
           {
           string pcode = Request.QueryString["pCode"].ToString();
           var query = from p in ds.Products
                       where p.pProductCode == pcode
                       select p;
           ListView1.DataSource = query;
           ListView1.DataBind();
           }

       }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Basket b;
        BasketItem bi = new BasketItem();
        if (Session["MyCart"] != null)
        {
            b = Session["MyCart"] as Basket;
        }
        else
        {
            b = new Basket();
        }

        string pcode = Request.QueryString["pCode"].ToString();
        Product p1 = ds.Products.FirstOrDefault(p => p.pProductCode == pcode);
        bi.ProductCode = p1.pProductCode;
        bi.Quantity = 1;
        bi.Price = Convert.ToInt32(p1.pPrice);
        b.Add(bi);
        Session["MyCart"] = b;
    }
}